<%@ page import="com.scalar.chiptrack.utils.ConfigManager,
                 com.scalar.forecast.forecastEntry.SearchField,
                 java.util.ArrayList,
                 com.scalar.forecast.forecastEntry.forms.ForecastEntrySearchForm,
                 com.scalar.forecast.commons.Constants,
                 com.scalar.forecast.forecastSetup.ForecastEntryField"%>
<%@ taglib uri="/WEB-INF/struts-html.tld"  prefix="html"%>
<%@ taglib uri="/WEB-INF/struts-logic.tld"  prefix="logic"%>
<%@ taglib uri="/WEB-INF/struts-nested.tld"  prefix="nested"%>
<%@ taglib uri="/WEB-INF/struts-bean.tld"  prefix="bean"%>
<%@ taglib uri="/WEB-INF/chiptrack-tags.tld" prefix="chiptrack" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>Scalarsoft - ChipTrac</TITLE>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<%String chipTracContext = "/" + ConfigManager.getChipTracContext();%>

<LINK href="<%=chipTracContext%>/jsp/includes/stylesheets/scalarsoft.css" type=text/css rel=stylesheet>
<%
    String isBuild = ( String )request.getAttribute ( Constants.FORECAST_IS_BUILD );
%>
<SCRIPT language=JavaScript src="<%=chipTracContext%>/jsp/includes/scripts/validations.js">
</SCRIPT>
<SCRIPT language=JavaScript src="<%=chipTracContext%>/jsp/includes/scripts/functions.js">
</SCRIPT>
<SCRIPT>
		   function openEditColumnWindow()
		   {
				newWindow = window.open ('forecast_entry_edit_column_display.html','editColumnPopup','channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=yes,scrollbars=auto,width=525 height=400,resizable=yes,left=300,top=130');
				 newWindow.focus();
		   }
		   function openExportFileWindow()
		   {
				newWindow = window.open ('export_to_file.html','exportToFilePopup','channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=yes,scrollbars=no,width=300 height=270,resizable=no,left=550,top=180');
				 newWindow.focus();
		   }
           function loadDetails( ctrl )
           {
                var form = document.forecastEntrySearchForm;
                if ( typeof ctrl == 'undefined' )
                {
                    return;
                }
                var orderByValue;
                if ( form.orderBy.length != null )
                {
                    for ( i=0; i < form.orderBy.length; i++ )
                    {
                        if ( form.orderBy[i].checked == true )
                            orderByValue = form.orderBy[i].value.trim();
                    }
                    ctrlName = ctrl.name;
                    if ( orderByValue == '<%=Constants.FORECAST_SETUP_BY_CUSTOMER%>' )
                    {
                        if ( ctrlName == 'custId' )
                        {
                            if ( form.projectId != null )
                            {
                                form.projectId.value = '-1';
                                form.action = "forecastEntrySearchAction.do?action=searchBuildLoadValues";
                                form.submit();
                            }
                            else if ( form.odmId != null )
                            {
                                form.action = "forecastEntrySearchAction.do?action=searchBuildLoadValues";
                                form.submit();
                            }
                        }
                        else if ( ctrlName == 'projectId' )
                        {
                            form.action = "forecastEntrySearchAction.do?action=searchBuildLoadValues";
                            form.submit();
                        }
                    }
                    else if ( orderByValue == '<%=Constants.FORECAST_SETUP_BY_PRODUCT%>' )
                    {
                        if ( ctrlName == 'productId' )
                        {
                            if ( form.projectId != null )
                            {
                                form.projectId.value = '-1';
                                form.custId.value = '-1';
                                form.action = "forecastEntrySearchAction.do?action=searchBuildLoadValues";
                                form.submit();
                            }
                        }
                        if ( ctrlName == 'projectId' )
                        {
                            form.custId.value = '-1';
                            form.action = "forecastEntrySearchAction.do?action=searchBuildLoadValues";
                            form.submit();
                        }
                        if ( ctrlName == 'custId' )
                        {
                            if ( form.odmId != null )
                            {
                                form.action = "forecastEntrySearchAction.do?action=searchBuildLoadValues";
                                form.submit();
                            }
                        }
                    }
                    else if ( orderByValue == '<%=Constants.FORECAST_SETUP_BY_PROJECT%>' )
                    {
                        if ( ctrlName == 'projectId' )
                        {
                            form.productId.value = '-1';
                            form.custId.value = '-1';
                            form.action = "forecastEntrySearchAction.do?action=searchBuildLoadValues";
                            form.submit();
                        }
                        else if ( ctrlName == 'custId' )
                        {
                            if ( form.odmId != null )
                            {
                                form.action = "forecastEntrySearchAction.do?action=searchBuildLoadValues";
                                form.submit();
                            }
                        }
                    }
                }

              /*  var form = document.forecastEntrySearchForm;
                if ( typeof ctrl == 'undefined' )
                {
                    return;
                }
                ctrlName = ctrl.name;
                if ( ctrlName == 'custId' )
                {
                    if ( form.projectId != null )
                    {
                        form.projectId.value = '-1';
                        form.action = "forecastEntrySearchAction.do?action=searchBuildLoadValues";
                        form.submit();
                    }
                    else if ( form.odmId != null )
                    {
                        form.action = "forecastEntrySearchAction.do?action=searchBuildLoadValues";
                        form.submit();
                    }
                }
                else if ( ctrlName == 'projectId' )
                {
                    form.action = "forecastEntrySearchAction.do?action=searchBuildLoadValues";
                    form.submit();
                } */
           }
           errors = "";
           function onSubmit()
           {
                var form =  document.forecastEntrySearchForm;
                errors = "";
                var pa  = document.getElementById ( 'errorsId' );
                pa.innerHTML = "";
                form.search.value = "true";
                form.action = "<%=chipTracContext%>/forecastEntrySearchAction.do?action=searchBuild";
                form.submit();
           }
           function loadValues()
           {
                var form =  document.forecastEntrySearchForm;
                if ( form.custId != null )
                    form.custId.value = '-1';
                if ( form.odmId != null )
                    form.odmId.value = '-1';
                if ( form.productId != null )
                    form.productId.value = '-1';
                if ( form.projectId != null )
                    form.projectId.value = '-1';

                form.action = "forecastEntrySearchAction.do?action=searchBuildLoadValues";
                form.submit();
           }
        </SCRIPT>

<META content="MSHTML 6.00.2800.1458" name=GENERATOR></HEAD>
<BODY bgColor=#ffffff leftMargin=0 topMargin=0 marginwidth="0" marginheight="0">
<!-- Top Header Start-->
<%@ include file="/jsp/includes/header.jsp" %>
<!-- Top Header End-->
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0><!--TBODY-->
  <TBODY>
  <TR>
    <TD vAlign=top width=180 background="<%=chipTracContext%>/jsp/includes/images/left_red_bg.gif">
  <!-- Side Navigation start -->
    <%@ include file="/jsp/marketing/marketing_menu.jsp" %>
 <!-- end of the side navigations -->
    <TD bgColor=#ffffff><IMG height=9
      src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=8></TD>
    <TD bgColor=#ffffff><IMG height=480
      src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=10></TD>
    <TD vAlign=top width="100%"><IMG height=1
      src="<%=chipTracContext%>/jsp/includes/images/clear.gif" width=500 border=0> <BR>
<!-- from here your body starts -->
<html:form action="/forecastEntrySearchAction" name="forecastEntrySearchForm" type="com.scalar.forecast.forecastEntry.forms.ForecastEntrySearchForm" onsubmit="onSubmit();">
<%-- this hidden field is used to whether do the search or not --%>
<input type="hidden" name="search" value="" >
      <TABLE width="100%" align=center border=0>
        <TBODY>
        <TR>
          <TD class=NArialW align=middle colSpan=5>Build Forecast Search</TD></TR>
        <TR>
          <TD colSpan=5>&nbsp;</TD></TR>
        <TR><TD colspan='5' id='errorMessagesId'><chiptrack:errors styleClass='NArialL' /></TD></TR>
        <TR><TD colspan='5' id='infoMessagesId'><chiptrack:info styleClass='NArialL' /></TD></TR>
        <TR><TD colspan='5' class="NArialL"><FONT id="errorsId"  color='FF0000'></FONT></TD></TR>
        <TR>
            <TD colspan=5 class="NArialL">
                <logic:iterate name="forecastSetupFields" id="setupField" scope="request">
                    <logic:equal name="setupField" property="entrySelected" value="true">
                        <logic:notEqual name="setupField" property="entryName" value="By ODM">
                            <nested:radio property="orderBy" value="<%=( ( ForecastEntryField )setupField ).getEntryName()%>" onclick="loadValues();"/><bean:write name="setupField" property="entryName"/>&nbsp;&nbsp;&nbsp;
                        </logic:notEqual>
                    </logic:equal>
                </logic:iterate>
            </TD>
        </TR>
        <TR>
          <TD colSpan=5>&nbsp;</TD></TR>
        <TR>
          <TD>
            <TABLE width="100%" border=0>
              <TBODY>
              <% int tdIdxCnt = 0; %>
              <nested:iterate property="searchFieldList" indexId="idx" id="searchField">
                <nested:equal property="display" value="true">
                   <% Integer tdidx = new Integer ( (++tdIdxCnt)%2 );
                      pageContext.setAttribute( "tdidx",tdidx );%>
                   <logic:equal name="tdidx" value="1" scope="page">
                      <TR>
                        <TD width="20%"><FONT class=NArialL><nested:write property="displayName"/>:</FONT></TD>
                        <TD class=NArialL width="25%">
                            <nested:equal property="type" value="select">
                                <html:select name="forecastEntrySearchForm" property='<%=(( SearchField )searchField).getPropertyName()%>' styleClass="txfield" onchange="loadDetails(this)">
                                    <% ArrayList propValues = (( SearchField )searchField).getPropertyValues();
                                        pageContext.setAttribute( "propertyValues", propValues);%>
                                    <html:options collection="propertyValues" property="value" labelProperty="label" />
                                </html:select>
                            </nested:equal>
                            <nested:equal property="type" value="text">
                                <html:text name="forecastEntrySearchForm" property='<%=(( SearchField )searchField).getPropertyName()%>' styleClass="txfield" size='15'/>
                            </nested:equal>

                       </TD>
                   </logic:equal>
                   <logic:equal name="tdidx" value="0" scope="page">
                        <TD width="5%">&nbsp;</TD>
                        <TD class=NArialL width="20%"><nested:write property="displayName"/>:</TD>
                        <TD class=NArialL width="30%">
                            <nested:equal property="type" value="select">
                                <html:select name="forecastEntrySearchForm" property='<%=(( SearchField )searchField).getPropertyName()%>' styleClass="txfield" onchange="loadDetails(this)">
                                    <% ArrayList propValues = (( SearchField )searchField).getPropertyValues();
                                        pageContext.setAttribute( "propertyValues", propValues);%>
                                    <html:options collection="propertyValues" property="value" labelProperty="label" />
                                </html:select>
                            </nested:equal>
                            <nested:equal property="type" value="text">
                                <html:text name="forecastEntrySearchForm" property='<%=(( SearchField )searchField).getPropertyName()%>' styleClass="txfield" size='15' />
                            </nested:equal>
                       </TD>
                     </TR>
                   </logic:equal>
                </nested:equal>
              </nested:iterate>

              <TR>
                <TD bgColor=#ffffff><IMG height=9
                  src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=8></TD></TR>

            <TR>
                <TD width="100%" colSpan=5 align="center">
                    <A href="javascript:onSubmit();"><IMG
					onmouseover="window.status='Click to Search';return true"
					title="Click to Search"
					onmouseout="window.status='';return true" height=17
					src="<%=chipTracContext%>/jsp/includes/images/search.gif" width=53
					border=0></A>&nbsp;&nbsp;&nbsp;&nbsp;
                  <A href="javascript:document.forecastEntrySearchForm.reset();"><IMG
					onmouseover="window.status='Click to Reset';return true"
					title="Click here to Reset"
					onmouseout="window.status='';return true"
					src="<%=chipTracContext%>/jsp/includes/images/reset.gif"
					border=0 width="53" height="17"></A>
                </TD>
            </TR>
            <TR>
                <TD  class="NArialL" colspan=5>To add a new Build, please <A href="forecastEntryBuildAction.do?action=search">Click here</A></TD>
            </TR>
            <TR>
                <TD bgColor=#ffffff><IMG height=9
                  src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=8></TD></TR>
            <TR>
                <TD colspan=5>
                    <!-- Search results table starts here -->
                    <logic:equal name="showBuildNumbers" value="true">
                    <TABLE width="100%">
                        <TR>
                            <TD width="50%" align="center" bgcolor="#993333"><FONT class="NArialL"><FONT color="#FFFFFF">Build Number</FONT></TD>
                            <TD width="100%" align="center" bgcolor="#993333"><FONT class="NArialL"><FONT color="#FFFFFF">Action</FONT></TD>
                        </TR>
                        <logic:iterate name="buildNumbers" indexId="idx" id="labelValueBean" scope="request">
                            <TR>
                                <TD width="50%" align="center" bgcolor='<%= (idx.intValue()%2) == 0 ? "#FFFFEE" : "#DEE1E2"%>'><FONT class="NArialL"><bean:write property="label" name="labelValueBean"/></FONT></TD>
                                <TD width="50%" align="center" bgcolor='<%= (idx.intValue()%2) == 0 ? "#FFFFEE" : "#DEE1E2"%>'><FONT class="NArialL"><A href='forecastEntrySearchAction.do?action=buildView&buildNo=<bean:write property="value" name="labelValueBean"/>'>View</A></FONT></TD>
                            </TR>
                        </logic:iterate>
                    </TABLE>
                    </logic:equal>
                    <!-- Search results table ends here -->
                </TD>
            </TR>
            </TBODY></TABLE></TD></TR>
</html:form>

        <TR>
          <TD><IMG src="<%=chipTracContext%>/jsp/includes/images/spacer.gif"
width=10></TD></TR>


		 </TBODY></TABLE></TD>

<!-- Footer starts here -->
<%@ include file="/jsp/includes/footer.jsp" %>
<!-- footer end here -->
</BODY>
</HTML>
